//
//  ViewController.m
//  test1
//
//  Created by chen on 16/10/29.
//  Copyright © 2016年 chen. All rights reserved.
//

#import "ViewController.h"
#import "TuijianViewController.h"
#import "DiscoverViewController.h"
#import "MessageViewController.h"
#import "MineViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addChildViewControlles];
}

- (void)addChildViewControlles {
    
    NSMutableArray *vcs = [NSMutableArray array];
    // 添加子控制器
    [vcs addObject:[self childVcWithClsName:[TuijianViewController class] title:@"推荐" imageName:@"tabbar_home" state: 1]];
    [vcs addObject:[self childVcWithClsName:[DiscoverViewController class] title:@"发现" imageName:@"tabbar_discover" state: 1]];
    [vcs addObject:[self childVcWithClsName:[MessageViewController class] title:@"消息" imageName:@"tabbar_message_center" state: 1]];
    [vcs addObject:[self childVcWithClsName:[MineViewController class] title:@"我的" imageName:@"tabbar_music" state: 0]];
    // 设置子控制器
    self.viewControllers = vcs.copy;
}

- (UIViewController *)childVcWithClsName:(Class)cla title:(NSString *)title imageName:(NSString *)imageName state:(BOOL)isNavi{
    // 断言:用来预先判断某一个添加一定成立,如果条件不成立,则直接崩溃
    NSAssert([cla isSubclassOfClass:[UIViewController class ]], @"cla类型一定要是UIViewContller的类型");
    // 创建子控制器
    UIViewController *vc = [[cla alloc] init];
    // 设置标题
    vc.title = title;
    // 设置tabBarItem的图片
    vc.tabBarItem.image = [UIImage imageNamed:imageName];
    // 创建导航控制器
    return  isNavi == 1? [[UINavigationController alloc] initWithRootViewController:vc]:vc;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
